#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n,m;
    cin>>n>>m;
    vector<int> a1(n+1),a2(m+1);
    for(int i=1;i<=n;i++)
        cin>>a1[i];
    for(int i=1;i<=m;i++)
        cin>>a2[i];
    sort(a1.begin()+1,a1.end());
    sort(a2.begin()+1,a2.end());
    int left=1,right=1;
    int last=0;
    while(left<=n || right<=m)
    {
        while(left<=n && a1[left]<=last)
            left++;
        while(right<=m && a2[right]<=last)
            right++;
        if(left<=n && right<=m)
        {
            if(a1[left]<a2[right] && a1[left]>last)
            {
                cout<<a1[left]<<' ';
                last=a1[left];
                left++;   
            }
            else if(a2[right]>last){
                cout<<a2[right]<<' ';
                last=a2[right];
                right++;
            }
        }
        else if(left<=n)
        {
            cout<<a1[left]<<' ';
            left++;
        }
        else if(right<=m)
        {
            cout<<a2[right]<<' ';
            right++;
        }
    }
    return 0;
}
